package com.yao.yaoojbackendjudgeservice.judge;

import com.yao.yaoojbackendjudgeservice.judge.strategy.DefaultJudgeStrategy;
import com.yao.yaoojbackendjudgeservice.judge.strategy.JavaLanguageJudgeStrategy;
import com.yao.yaoojbackendjudgeservice.judge.strategy.JudgeContext;
import com.yao.yaoojbackendjudgeservice.judge.strategy.JudgeStrategy;
import com.yao.yaoojbackendmodel.model.codesandbox.JudgeInfo;
import com.yao.yaoojbackendmodel.model.entity.Question;
import com.yao.yaoojbackendmodel.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**
 * 选择判题方法策略（简化调用）
 */
@Service
public class JudgeManage {


    /**
     * 判题
     * @param judgeContext
     * @return
     */
    public JudgeInfo doJudge(JudgeContext judgeContext){
        JudgeStrategy judgeStrategy=new DefaultJudgeStrategy();
        Question question=judgeContext.getQuestion();
        QuestionSubmit questionSubmit=judgeContext.getQuestionSubmit();
        String language=questionSubmit.getLanguage();
        if("java".equals(language)){
            judgeStrategy=new JavaLanguageJudgeStrategy(); //返回值是实现的接口类型JudgeStrategy
        }
        return judgeStrategy.doJudge(judgeContext);
    }
}
